package cn.tedu.pojo;

import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;

@RestController
@RequestMapping("user")
public class User {
    @RequestMapping("save/{id}/{x}/{age}")
    public void save(@PathVariable Integer id, @PathVariable String x, @PathVariable Integer age){
        System.out.println(id+x+age);
    }
    @RequestMapping("save2")
    public void save2(Integer id,String name,Integer age){
//                System.out.println(id+name+age);
        try {
            Class.forName("com.mysql.jdbc.Driver");
            Connection conn = DriverManager.getConnection("jdbc:mysql:///mydemo1","root","root");
            String sql ="insert into user values (?,?,?)";
            PreparedStatement ps = conn.prepareStatement(sql);
            ps.setInt(1,id);
            ps.setString(2,name);
            ps.setInt(3,age);
            int rows = ps.executeUpdate();

            conn.close();
        } catch (Exception e) {
            e.printStackTrace();
            System.out.println("代码错误");
        }
    }
}
